package at.kokoni.Koko_Ni.entities;

import java.io.Serializable;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.annotations.SerializedName;

public class ApiResponse implements Serializable {
	@SerializedName("return")
	private int returnValue;

	@SerializedName("error")
	private String errorValue;

	@SerializedName("data")
	private String dataValue;

	public ApiResponse() {
	}

	public static ApiResponse responseFromJson(String json) {
		ApiResponse response = new ApiResponse();
		JsonParser parser = new JsonParser();
		JsonObject object = (JsonObject) parser.parse(json);
		response.returnValue = object.getAsJsonPrimitive("return").getAsInt();
		if (response.returnValue == 0) {
			JsonElement o = object.get("data");
			response.dataValue = o.toString();
		} else {
			response.errorValue = object.getAsJsonPrimitive("error").getAsString();
		}
		return response;
	}

	public int getReturnValue() {
		return returnValue;
	}

	public String getErrorValue() {
		return errorValue;
	}

	public String getDataValue() {
		return dataValue;
	}
}
